package views.report;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JSeparator;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.ActionEvent;

public class SalesReportView extends JPanel{
	private JLabel lblCategory;
	private JComboBox categorycombo;
	private JComboBox sellernamecombo;
	private JButton btnfilter;
	private JTable table;
	private JScrollPane scrollPane;
	private JButton btnToDate;
	private JButton btnFromDate;
	private JTextField ttodate;
	private JTextField tfromdate;
	private JButton btnPrint;
	
	public SalesReportView() 
	{
		SpringLayout springLayout = new SpringLayout();
		setLayout(springLayout);
	
		setSize(870,550);
		
		tfromdate = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, tfromdate, 30, SpringLayout.NORTH, this);
		tfromdate.setText("From Date");
		springLayout.putConstraint(SpringLayout.WEST, tfromdate, 30, SpringLayout.WEST, this);
		tfromdate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 11));
		tfromdate.setColumns(7);
		add(tfromdate);
		
		btnFromDate = new JButton("Cl1");
		btnFromDate.setActionCommand("Cl1");
		springLayout.putConstraint(SpringLayout.NORTH, btnFromDate, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnFromDate, 10, SpringLayout.EAST, tfromdate);
		add(btnFromDate);
		
		ttodate = new JTextField();
		springLayout.putConstraint(SpringLayout.NORTH, ttodate, 30, SpringLayout.NORTH,this);
		ttodate.setText("To Date");
		springLayout.putConstraint(SpringLayout.WEST, ttodate, 10, SpringLayout.EAST,btnFromDate);
		ttodate.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 11));
		ttodate.setColumns(7);
		add(ttodate);
		
		btnToDate = new JButton("Cl");
		btnToDate.setActionCommand("Cl");
		springLayout.putConstraint(SpringLayout.NORTH, btnToDate, 30, SpringLayout.NORTH,this);
		springLayout.putConstraint(SpringLayout.WEST, btnToDate, 10, SpringLayout.EAST,ttodate);
		add(btnToDate);
		
		lblCategory = new JLabel("Category");
		lblCategory.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, lblCategory, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.NORTH, lblCategory, 20, SpringLayout.SOUTH,tfromdate );
		add(lblCategory);
		
		categorycombo = new JComboBox();
		categorycombo.setModel(new DefaultComboBoxModel(new String[] {"--Select Catagory--"}));
		categorycombo.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 11));
		springLayout.putConstraint(SpringLayout.NORTH, categorycombo, 6, SpringLayout.SOUTH,lblCategory);
		springLayout.putConstraint(SpringLayout.WEST, categorycombo, 30, SpringLayout.WEST, this);
		add(categorycombo);
		categorycombo.setPreferredSize(new Dimension(200, 23));
		
		JLabel lblSellerName = new JLabel("Seller Name");
		lblSellerName.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 13));
		springLayout.putConstraint(SpringLayout.WEST, lblSellerName, 30, SpringLayout.EAST,categorycombo);
		springLayout.putConstraint(SpringLayout.NORTH, lblSellerName, 0, SpringLayout.NORTH,lblCategory);
		add(lblSellerName);
		
		sellernamecombo = new JComboBox();
		sellernamecombo.setModel(new DefaultComboBoxModel(new String[] {"--Select Seller Name--"}));
		springLayout.putConstraint(SpringLayout.NORTH, sellernamecombo, 0, SpringLayout.NORTH,categorycombo);
		springLayout.putConstraint(SpringLayout.WEST, sellernamecombo, 30, SpringLayout.EAST,categorycombo);
		add(sellernamecombo);
		sellernamecombo.setPreferredSize(new Dimension(200, 23));
		
		btnfilter = new JButton("APPLY FILTER");
		btnfilter.setActionCommand("APPLY FILTER");
		btnfilter.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, btnfilter, 0, SpringLayout.NORTH,categorycombo);
		springLayout.putConstraint(SpringLayout.WEST, btnfilter, 30, SpringLayout.EAST,sellernamecombo);
		add(btnfilter);
		
		JSeparator separator = new JSeparator();
		springLayout.putConstraint(SpringLayout.WEST, separator, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, separator, -30, SpringLayout.EAST, this);
		springLayout.putConstraint(SpringLayout.NORTH, separator, 30, SpringLayout.SOUTH,categorycombo );
		add(separator);
		
		scrollPane = new JScrollPane();
		scrollPane.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 10));
		springLayout.putConstraint(SpringLayout.NORTH, scrollPane, 30, SpringLayout.SOUTH,separator);
		springLayout.putConstraint(SpringLayout.WEST, scrollPane, 30, SpringLayout.WEST, this);
		springLayout.putConstraint(SpringLayout.EAST, scrollPane, -30, SpringLayout.EAST, this);
		springLayout.putConstraint(SpringLayout.SOUTH, scrollPane, -30, SpringLayout.SOUTH, this);
		add(scrollPane);
		
		table = new JTable();
		table.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 10));
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"MCODE", "CATAGORY", "SELLER", "PURCHASE DATE", "PURCHASE Qty", "PURCHASE Amt", "TOTAL SELL", "REMAINDER Qty"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, true, false, false, false, false, false, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(1).setPreferredWidth(93);
		table.getColumnModel().getColumn(2).setPreferredWidth(103);
		table.getColumnModel().getColumn(3).setPreferredWidth(100);
		table.getColumnModel().getColumn(4).setPreferredWidth(116);
		table.getColumnModel().getColumn(5).setPreferredWidth(81);
		table.getColumnModel().getColumn(6).setPreferredWidth(117);
		scrollPane.setViewportView(table);
		
		btnPrint = new JButton("Print");
		btnPrint.setActionCommand("Print");
		btnPrint.setFont(new Font("MS Reference Sans Serif", Font.PLAIN, 12));
		springLayout.putConstraint(SpringLayout.NORTH, btnPrint, 10, SpringLayout.NORTH, this);
		springLayout.putConstraint(SpringLayout.EAST, btnPrint, -10, SpringLayout.EAST, this);
		add(btnPrint);
		
		
	}
	
	public JLabel getLblCategory() {
		return lblCategory;
	}
	public void setLblCategory(JLabel lblCategory) {
		this.lblCategory = lblCategory;
	}
	public JComboBox getCategorycombo() {
		return categorycombo;
	}
	public void setCategorycombo(JComboBox categorycombo) {
		this.categorycombo = categorycombo;
	}
	public JComboBox getSellernamecombo() {
		return sellernamecombo;
	}
	public void setSellernamecombo(JComboBox sellernamecombo) {
		this.sellernamecombo = sellernamecombo;
	}
	public JButton getBtnfilter() {
		return btnfilter;
	}
	public void setBtnfilter(JButton btnfilter) {
		this.btnfilter = btnfilter;
	}
	public JTable getTable() {
		return table;
	}
	public void setTable(JTable table) {
		this.table = table;
	}
	public void actionlistener(ActionListener al)
	{
		this.btnfilter.addActionListener(al);
	}

	public JScrollPane getScrollPane() {
		return scrollPane;
	}

	public void setScrollPane(JScrollPane scrollPane) {
		this.scrollPane = scrollPane;
	}

	public JButton getBtnToDate() {
		return btnToDate;
	}

	public void setBtnToDate(JButton btnToDate) {
		this.btnToDate = btnToDate;
	}

	public JButton getBtnFromDate() {
		return btnFromDate;
	}

	public void setBtnFromDate(JButton btnFromDate) {
		this.btnFromDate = btnFromDate;
	}

	public JTextField getTtodate() {
		return ttodate;
	}

	public void setTtodate(JTextField ttodate) {
		this.ttodate = ttodate;
	}

	public JTextField getTfromdate() {
		return tfromdate;
	}

	public void setTfromdate(JTextField tfromdate) {
		this.tfromdate = tfromdate;
	}

	public JButton getBtnPrint() {
		return btnPrint;
	}

	public void setBtnPrint(JButton btnPrint) {
		this.btnPrint = btnPrint;
		
	}
	public void actionlisteners(ActionListener al)
	{
		this.btnfilter.addActionListener(al);
		this.btnFromDate.addActionListener(al);
		this.btnPrint.addActionListener(al);
		this.btnToDate.addActionListener(al);
	}
}
